package com.menu.web.controller.training;

import com.menu.common.annotation.Log;
import com.menu.common.core.controller.BaseController;
import com.menu.common.core.domain.AjaxResult;
import com.menu.common.core.page.TableDataInfo;
import com.menu.common.enums.BusinessType;
import com.menu.common.utils.poi.ExcelUtil;
import com.menu.system.domain.MenuTraining;
import com.menu.system.service.IMenuTrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 培训信息Controller
 *
 * @author ruoyi
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/system/training")
public class MenuTrainingController extends BaseController {
    @Autowired
    private IMenuTrainingService menuTrainingService;

    /**
     * 查询培训信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:training:list')")
    @GetMapping("/list")
    public TableDataInfo list(MenuTraining menuTraining) {
        startPage();
        List<MenuTraining> list = menuTrainingService.selectMenuTrainingList(menuTraining);
        return getDataTable(list);
    }

    /**
     * 导出培训信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:training:export')")
    @Log(title = "培训信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuTraining menuTraining) {
        List<MenuTraining> list = menuTrainingService.selectMenuTrainingList(menuTraining);
        ExcelUtil<MenuTraining> util = new ExcelUtil<MenuTraining>(MenuTraining.class);
        util.exportExcel(response, list, "培训信息数据");
    }

    /**
     * 获取培训信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:training:query')")
    @GetMapping(value = "/{trainId}")
    public AjaxResult getInfo(@PathVariable("trainId") Long trainId) {
        return success(menuTrainingService.selectMenuTrainingByTrainId(trainId));
    }

    /**
     * 新增培训信息
     */
    @PreAuthorize("@ss.hasPermi('system:training:add')")
    @Log(title = "培训信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuTraining menuTraining) {
        return toAjax(menuTrainingService.insertMenuTraining(menuTraining));
    }

    /**
     * 修改培训信息
     */
    @PreAuthorize("@ss.hasPermi('system:training:edit')")
    @Log(title = "培训信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuTraining menuTraining) {
        return toAjax(menuTrainingService.updateMenuTraining(menuTraining));
    }

    /**
     * 删除培训信息
     */
    @PreAuthorize("@ss.hasPermi('system:training:remove')")
    @Log(title = "培训信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{trainIds}")
    public AjaxResult remove(@PathVariable Long[] trainIds) {
        return toAjax(menuTrainingService.deleteMenuTrainingByTrainIds(trainIds));
    }
}
